/*************************************************
 *FileName:      newmsg.js
 *Description:   朋友圈新消息.js
 *Others:        陈灿
 *************************************************/
    /*
     * 启动
     */
    mui.init();
    mui('.mui-scroll-wrapper').scroll({
        indicators: false,      //是否显示滚动条 默认为true
        deceleration: 0.003,    //阻尼系数,系数越小滑动越灵敏 默认0.0006
        bounce: true           //是否启用回弹 默认true
    });
    /*
     * 变量初始化
     */
    var uid = localStorage.replace_uid;
    var token = localStorage.replace_token;
    var page_num=20,page=1,ids=[];
    var open=true, oface ;
    /*
     * 主程序
     */ 
    $(document).ready(function() 
    {
        //样式加载
        pagecss();
    });
    mui.init({
        beforeback: function() {
            var list = plus.webview.currentWebview().opener();
            mui.fire(list, 'circlefriends');
            return true;
        }
    });
    /**
     * pagecss
     * 样式加载
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function pagecss(){
        $('.main').on('tap','.con .imgs',function(){
            if($(this).hasClass('img')){
                $('.img-look').addClass('active')
                var ourl =  $(this).attr('src');
                $('.img-look-box').html('<img src="'+ourl+'"/>')
                return false;
            }
        })
        
        $('.main').on('tap','.con',function(){
            var articleid = $(this).attr('data-articleid');
            common.pageTransition('particulars.html?id='+articleid)
        })
        
        
        $('.img-look').on('tap',function(){
            $('.img-look').removeClass('active')
        })
        
        $('.main').on('tap','.top',function(){
            var suid = $(this).attr('data-suid');
            common.pageTransition('particulars.html?id='+suid)
        })
        
        $.ajax({
            type: "post",
            url: DOMAIN_NAME + "/index.php/api/Article_Comment/getNewCommentList",
            dataType: 'jsonp',
            data: {uid:uid,token:token},
            success: function(data) {
                var ohtml='';
                if(data.error_code == 0) {
                    for(var i=0 ;i<data.data.length ; i++){
                        if(data.data[i].face){
                            oface =DOMAIN_NAME+data.data[i].face;
                        }else{
                            oface ='images/myimg.jpg';
                        }
                        var ocontent = data.data[i].comment.replace(/\.\?\./g,"'");
                        ohtml+='<div class="con" data-articleid="'+data.data[i].article_id+'" data-id="'+data.data[i].id+'"> <div class="cont">'
                             +'<img class="top" data-suid="'+data.data[i].to_uid+'" src="'+oface+'"/>'
                             +'<div class="text"><p class="name">'+data.data[i].nickname+'</p>'
                             +'<p class="content">'+ocontent+'</p><p class="time">'+timesub(data.data[i].comment_time)+'</p>'
                        if(data.data[i].type==2){
                             ohtml+='</div><img class="imgs" src="'+data.data[i].thumb+'"/><em class="vdo"></em></div></div>'
                        }else if(data.data[i].type==1){
                             ohtml+='</div><img class="imgs img" src="'+DOMAIN_NAME+data.data[i].thumb+'"/></div></div>'
                        }else{
                             ohtml+='</div><div class="textwz" >'+data.data[i].content+'</div></div></div>'
                        }
                        ids.push(data.data[i].id);
                    }
                    $('.main').html(ohtml);
                } else if(data.error_code == 1001) {
                    setTimeout(function() {
                        exitlogin();
                    },1000);
                } else {
                }
            }
        });
    }
    
    $('.more').on('tap',function(){
        if(open){
            list();
        }
        open=false;
    })
    
    function list(){
        $.ajax({
            type: "post",
            url: DOMAIN_NAME + "/index.php/api/Article_Comment/getMyCommentList",
            dataType: 'jsonp',
            data: {uid:uid,token:token,page:page,page_num:page_num,ids:ids},
            success: function(data) {
                var ohtml='';
                if(data.error_code == 0) {
                    if(data.data.length == page_num){
                        $('.mui-scroll').children('.more').html('查看更早的消息...');
                        open = true;
                    }else{
                        $('.mui-scroll').children('.more').html('没有更多了');
                        open = false;
                    }
                    for(var i=0 ;i<data.data.length ; i++){
                        if(data.data[i].face){
                            oface =DOMAIN_NAME+data.data[i].face;
                        }else{
                            oface ='images/myimg.jpg';
                        }
                        var ocontent = data.data[i].comment.replace(/\.\?\./g,"'");
                        ohtml+='<div class="con" data-articleid="'+data.data[i].article_id+'" data-id="'+data.data[i].id+'"> <div class="cont">'
                             +'<img class="top" data-suid="'+data.data[i].to_uid+'" src="'+oface+'"/>'
                             +'<div class="text"><p class="name">'+data.data[i].nickname+'</p>'
                             +'<p class="content">'+ocontent+'</p><p class="time">'+timesub(data.data[i].comment_time)+'</p>'
                        if(data.data[i].type==2){
                             ohtml+='</div><img class="imgs" src="'+data.data[i].thumb+'"/><em class="vdo"></em></div></div>'
                        }else if(data.data[i].type==1){
                             ohtml+='</div><img class="imgs img" src="'+DOMAIN_NAME+data.data[i].thumb+'"/></div></div>'
                        }else{
                             ohtml+='</div><div class="textwz" >'+data.data[i].content+'</div></div></div>'
                        }
                    }
                    $('.main').append(ohtml);
                    page++;
                } else if(data.error_code == 1001) {
                    setTimeout(function() {
                        exitlogin();
                    },1000);
                } else {
                    $('.mui-scroll').children('.more').html('没有更多了');
                    open = false;
                }
            }
        });
    }